package com.test;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

public class Json {
	public static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	public static String str = "{\"errcode\":0,\"errmsg\":\"ok\",\"info\":{\"sp_no\":\"202107140023\",\"sp_name\":"
			+ "\"加班\",\"sp_status\":2,\"template_id\":\"Bs2iMv3Cv1RtTNiNapeMiegBZWJrwxkyU17srQZrs\",\"apply_time\":1"
			+ "626254037,\"applyer\":{\"userid\":\"18871857790\",\"partyid\":\"1\"},\"sp_record\":[{\"sp_status\":2,\""
			+ "approverattr\":1,\"details\":[{\"approver\":{\"userid\":\"18871857790\"},\"speech\":\"\",\"sp_status\":2,"
			+ "\"sptime\":1626254043,\"media_id\":[]}]}],\"notifyer\":[{\"userid\":\"18871857790\"}],\"apply_data\":{\"conte"
			+ "nts\":[{\"control\":\"Textarea\",\"id\":\"item-item-1493800414708\",\"title\":[{\"text\":\"加班事由\",\"lang\":\"zh_"
			+ "CN\"}],\"value\":{\"text\":\"这是一个加班申请\",\"tips\":[],\"members\":[],\"departments\":[],\"files\":[],\"children\":[],\"stat_"
			+ "field\":[],\"sum_field\":[],\"related_approval\":[],\"students\":[],\"classes\":[]}},{\"control\":\"Attendance\",\"id\":\"smart-t"
			+ "ime\",\"title\":[{\"text\":\"加班\",\"lang\":\"zh_CN\"}],\"value\":{\"tips\":[],\"members\":[],\"departments\":[],\"files\":[],\"child"
			+ "ren\":[],\"stat_field\":[],\"attendance\":{\"date_range\":{\"type\":\"hour\",\"new_begin\":1626167580,\"new_end\":1626253980,\"new_dura"
			+ "tion\":86400},\"type\":5,\"slice_info\":{\"day_items\":[{\"daytime\":1626105600,\"time_sections\":[],\"duration\":24480},{\"daytime\":162619"
			+ "2000,\"time_sections\":[],\"duration\":61920}],\"state\":1,\"duration\":86400}},\"sum_field\":[],\"related_approval\":[],\"students\":[],\"clas"
			+ "ses\":[]}},{\"control\":\"Contact\",\"id\":\"Contact-1624343957239\",\"title\":[{\"text\":\"成员\",\"lang\":\"zh_CN\"}],\"value\":{\"tips\":[],\"memb"
			+ "ers\":[{\"userid\":\"15007100521\",\"name\":\"任涛\"},{\"userid\":\"13971090065\",\"name\":\"查明威\"},{\"userid\":\"ZhuHaiTao\",\"name\":\"朱海涛\"}],\"depa"
			+ "rtments\":[],\"files\":[],\"children\":[],\"stat_field\":[],\"sum_field\":[],\"related_approval\":[],\"students\":[],\"classes\":[]}}]},\"comments\":[]}}";
	public static void main(String[] args) {
		List<String> userlist = new ArrayList<String>();
		JSONObject json = JSONObject.parseObject(str);
		JSONObject info =  json.getJSONObject("info");		
		String type = info.getString("sp_name");
		switch (type) {
		case "加班":
			
			String send_user = info.getJSONObject("applyer").getString("userid");
			userlist.add(send_user);			
			JSONObject apply_data =  info.getJSONObject("apply_data");
			JSONArray contents =  apply_data.getJSONArray("contents");
			JSONObject content0 = JSONObject.parseObject(contents.get(0).toString());
			JSONObject content1 = JSONObject.parseObject(contents.get(1).toString());
			JSONObject content2 = JSONObject.parseObject(contents.get(2).toString());
			String text = content0.getJSONObject("value").getString("text");//加班说明
			JSONObject date_range = content1.getJSONObject("value").getJSONObject("attendance").getJSONObject("date_range");//加班时间控件
			String date_type = date_range.getString("type");//计算时长类型:hour/3600
			String new_begin = format.format(new Date(date_range.getLong("new_begin")));
			String new_end = format.format(new Date(date_range.getLong("new_end")));;
			String new_duration = date_range.getString("new_duration");
			
			System.err.println(String.format("%s+%s+%s+%s+%s+%s", type,text,date_type,new_begin,new_end,new_duration));
			//控件数组1：审批类型{加班，请假}；2：
			
			
			break;
		case "请假":
			
			
			break;
		default:
			break;
		}
		
		System.out.println(type);
	}
}
